<div class="modal-body pageContent">
    <div class="row">
        <div class="col-lg-12 col-lg-offset-2">
            <form id="productForm" method="post" class="form-horizontal" action="/product/addProductType">
                <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">名称</span></label>
                    <div class="col-lg-12">
                        <input type="text" class="form-control" class="name" name="name" value="{{name}}" />
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">运营商</span></label>
                    <div class="col-lg-12">
                        <input type="text" class="form-control" class="operator" name="operator" value="{{operator}}" />
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">PN</span></label>
                    <div class="col-lg-12">
                        <input type="text" class="form-control" class="pn" name="pn" value="{{pn}}" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal-footer pageFooter">
   <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
   <button  class="btn btn-primary" type="submit">保存</button>

</div>
<script type="text/javascript">
$(document).ready(function() {  
    $('.selectpicker').selectpicker();//初始化
    $('#productForm')
        .bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
             fields: {
                name: {
                    message: '名称不能为空',
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                },
                operator: {
                    message: '运营商不能为空',
                    validators: {
                        notEmpty: {
                            message: '运营商不能为空'
                        }
                    }
                },
                 pn: {
                    message: 'PN不能为空',
                    validators: {
                        notEmpty: {
                            message: 'PN不能为空'
                        }
                        // ,
                        //  regexp:{
                        //     regexp: /^[a-zA-Z0-9]{2,30}$/,
                        //     message:'PN只能由字母、数字组成,长度必须2到30之间'
                        // }
                    }
                }
            }
        })
        .on('success.form.bv', function(e) {
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            //console.log($form.serialize());
            // Use Ajax to submit form data
            $.ajax({
                type: 'post',
                url:$form.attr('action'),
                data:$form.serialize(),
                success: function(result){
                    if(result.length===9371){   //session超时返回的登录页面 避免接口返回的也是字符串不是json
                                location.href="/severError";
                    }else{  //正常处理
                        var resdata = result;
                        var getData= $("#productTypeTable").bootstrapTable('getData');
                        if(result.statusCode =='200'){
                                if('{{id}}'){
                                    for(var i=0;i<getData.length;i++){
                                        if(resdata.id==getData[i].id){
                                        getData[i]=resdata;
                                        delete getData[i];
                                    }
                                    }
                                }
                                    $('#productListAdd').modal('hide');
                                $("#productTypeTable").bootstrapTable('refresh',{url:"/product/getProductTypeList",silent:true});
                                    toastr.success(result.message+'!');
                        }else{
                            toastr.warning(result.message+'!');
                        } 
                    }
                },
                error: function (result) {       //后台数据异常返回503
                    if(result.status===503||result.status===500){ 
                        $('#productListAdd').modal('hide');
                        toastr.error("服务端数据异常"+'!');
                    }
                } 
            })
            // $.post($form.attr('action'), $form.serialize(), function(result) {
            //     var resdata = result;
            //     var getData= $("#productTypeTable").bootstrapTable('getData');
            //     if(result.statusCode =='200'){
            //               if('{{id}}'){
            //                 for(var i=0;i<getData.length;i++){
            //                     if(resdata.id==getData[i].id){
            //                        getData[i]=resdata;
            //                        delete getData[i];
            //                    }
            //                 }
            //               }
            //                 $('#productListAdd').modal('hide');
            //               $("#productTypeTable").bootstrapTable('refresh',{url:"/product/getProductTypeList",silent:true});
            //                  toastr.success(result.message+'!');
            //     }else{
            //         toastr.warning(result.message+'!');
            //     }
            // }, 'json');
        });

});

</script>
